package com.lzw.breadknife.util;

import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;

/**
 * 全局日志类
 * author  : AWeiLoveAndroid
 * e-mail  : lzw460433675@163.com
 * github  : https://gitee.com/AWeiLoveAndroid/BreadKnife
 * project : BreadKnife
 */
public class Logger {

    public static void logInfo(Messager messager, String message) {
        messager.printMessage(Diagnostic.Kind.NOTE, message);
    }

    public static void logInfo(ProcessingEnvironment processingEnv, String message) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
    }

    public static void logInfo(ProcessingEnvironment processingEnv, Element element, String message, Object... args) {
        if (args.length > 0) {
            message = String.format(message, args);
        }
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message, element);
    }

    public static void logWarning(Messager messager, String message) {
        messager.printMessage(Diagnostic.Kind.WARNING, message);
    }

    public static void logWarning(ProcessingEnvironment processingEnv, String message) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, message);
    }

    public static void logWarning(ProcessingEnvironment processingEnv, Element element, String message, Object... args) {
        if (args.length > 0) {
            message = String.format(message, args);
        }
        processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, message, element);
    }

    public static void logError(Messager messager, String message) {
        messager.printMessage(Diagnostic.Kind.ERROR, message);
    }

    public static void logError(ProcessingEnvironment processingEnv, String message) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message);
    }

    public static void logError(ProcessingEnvironment processingEnv, Element element, String message) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element);
    }

    public static void logError(ProcessingEnvironment processingEnv, Element element, String message, Object... args) {
        if (args.length > 0) {
            message = String.format(message, args);
        }
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element);
    }

}
